import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import OSS from 'ali-oss';

@Injectable()
export class OssService {
  private readonly client: OSS;

  constructor(private readonly config: ConfigService) {
    this.client = new OSS({
      region: this.config.get('oss.region'),
      bucket: this.config.get('oss.bucket'),
      accessKeyId: this.config.get('oss.accessKeyId'),
      accessKeySecret: this.config.get('oss.accessKeySecret'),
    });
  }

  public async put(
    name: string,
    file: any,
    options?: OSS.PutObjectOptions,
  ): Promise<OSS.PutObjectResult> {
    return await this.client.put(name, file, options);
  }
}
